﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Character : MonoBehaviour
{
    [SerializeField]
    private bool activeCharacterController;
    private Character detectCharacter;
    private SimpleExampleCharacterProperties properties;



    void Start()
    {
        CharacterPropertiesGroup dataGroup = new CharacterPropertiesGroup();
        dataGroup.Hero = gameObject;

        properties = new SimpleExampleCharacterProperties(dataGroup);
    }

    void Update()
    {
        if(activeCharacterController&&Input.GetKeyDown(KeyCode.Space))
        {
            Debug.Log("Hit now!");
            HitTarget();
        }
    }

    void OnTriggerEnter(Collider other)
    {
        var characterOnOther = other.GetComponent<Character>();
        
        if(!characterOnOther)
        {
            Debug.Log("与Character交互的对象上不存在Character！");
            return;
        }

        detectCharacter = characterOnOther;
    }


    private void HitTarget()
    {
        if(detectCharacter == null)
        {
            Debug.Log("No character is hit!");
            return;
        }

        var enemyHp = detectCharacter.properties.GetProperty("HP");
        var atk = detectCharacter.properties.GetProperty("atk");

        enemyHp.Sub(atk.Active);
    }
}
